package com.jch.dm.chapter_17_observer;

import java.util.Random;

/**
 * @author: Administrator
 * @create: 2020/04/08 11:48
 **/
public class RandomNumberGenerator extends NumberGenerator {

    /**
     * 随机数生成器
     */
    private Random random = new Random();
    /**
     * 当前数值
     */
    private int number;

    /**
     * 获取数值
     *
     * @return 数值
     */
    @Override
    public int getNumber() {
        return number;
    }

    /**
     * 生成数值
     */
    @Override
    public void execute() {
        for (int i = 0; i < 20; i++) {
            number = random.nextInt(50);
            notifyObservers();
        }
    }
}
